<?php
class AbiturientsPrioritetsController extends AppController {

	var $name = 'AbiturientsPrioritets';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->AbiturientsPrioritet->recursive = 0;
		$this->set('abiturientsPrioritets', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid AbiturientsPrioritet', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('abiturientsPrioritet', $this->AbiturientsPrioritet->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->AbiturientsPrioritet->create();
			if ($this->AbiturientsPrioritet->save($this->data)) {
				$this->Session->setFlash(__('The AbiturientsPrioritet has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The AbiturientsPrioritet could not be saved. Please, try again.', true));
			}
		}
		if ($this->params['named']['abiturient']){
			$this->AbiturientsPrioritet->Abiturient->id = $this->params['named']['abiturient'];
		}
		else {
			$this->AbiturientsPrioritet->Abiturient->id = $this->data['AbiturientsPrioritet']['abiturient_id'];
		}
				
		$prioritets = $this->AbiturientsPrioritet->Prioritet->find('list');
		//debug($prioritets);
		$abiturient = $this->AbiturientsPrioritet->Abiturient->read(array('Abiturient.lastname', 'Abiturient.firstname', 'Abiturient.surname', 'Abiturient.id'));
		$this->set(compact('prioritets', 'abiturient'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid AbiturientsPrioritet', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->AbiturientsPrioritet->save($this->data)) {
				$this->Session->setFlash(__('The AbiturientsPrioritet has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The AbiturientsPrioritet could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->AbiturientsPrioritet->read(null, $id);
		}
		$prioritets = $this->AbiturientsPrioritet->Prioritet->find('list');
		$abiturients = $this->AbiturientsPrioritet->Abiturient->find('list');
		$this->set(compact('prioritets','abiturients'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for AbiturientsPrioritet', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->AbiturientsPrioritet->del($id)) {
			$this->Session->setFlash(__('AbiturientsPrioritet deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The AbiturientsPrioritet could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}

}
?>